﻿package mortal.game.manager.mouse
{
    import com.gengine.core.call.*;
    import flash.display.*;
    import flash.events.*;

    public class MouseThreeClickRule extends Object implements IMouseRule
    {
        private var _target:InteractiveObject;
        private var _caller:Caller;
        private const callType:String = "MouseThreeClickCall";
        private const judgeTime:int = 1000;
        private var _downArray:Array;

        public function MouseThreeClickRule()
        {
            this._downArray = [];
            this._caller = new Caller();
            return;
        }// end function

        public function addCall(param1:Function) : void
        {
            this._caller.addCall(this.callType, param1);
            return;
        }// end function

        public function startRule() : void
        {
            if (!this._target)
            {
                return;
            }
            this._target.addEventListener(MouseEvent.MOUSE_DOWN, this.onMouseDown);
            return;
        }// end function

        private function onMouseDown(event:MouseEvent) : void
        {
            var _loc_3:Date = null;
            var _loc_4:Date = null;
            var _loc_2:* = new Date();
            this._downArray.push(_loc_2);
            if (this._downArray.length > 3)
            {
                this._downArray.shift();
            }
            if (this._downArray.length == 3)
            {
                _loc_3 = this._downArray[2] as Date;
                _loc_4 = this._downArray[0] as Date;
                if (_loc_3.time - _loc_4.time < 1000)
                {
                    this._caller.call(this.callType);
                    this._downArray = [];
                }
            }
            return;
        }// end function

        public function endRule() : void
        {
            this._target.removeEventListener(MouseEvent.MOUSE_DOWN, this.onMouseDown);
            this._downArray = [];
            this._target = null;
            return;
        }// end function

        public function set target(param1:InteractiveObject) : void
        {
            this._target = param1;
            return;
        }// end function

    }
}
